{% extends 'myadmin/base.html' %}
{% block main_body %}
<style>
    /* 保持原有样式 */
    .form-card {
        background: #fff;
        border-radius: 6px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        padding: 20px;
    }
    .form-section {
        margin-bottom: 20px;
        padding-bottom: 15px;
        border-bottom: 1px solid #f1f1f1;
    }
    .form-row {
        display: flex;
        flex-wrap: wrap;
        margin: 0 -10px;
    }
    .form-col {
        flex: 1;
        min-width: 300px;
        padding: 0 10px;
        box-sizing: border-box;
    }
    .form-group {
        margin-bottom: 12px;
        width: 100%;
    }
    .form-group label {
        font-weight: 600;
        font-size: 13px;
        margin-bottom: 5px;
        display: block;
    }
    .form-control {
        width: 100%;
        padding: 6px 10px;
        font-size: 13px;
        height: 34px;
        box-sizing: border-box;
    }
    .checkbox-group {
        display: flex;
        gap: 15px;
        margin-top: 8px;
    }
    .checkbox-item {
        display: flex;
        align-items: center;
        gap: 5px;
    }
    .btn-group {
        margin-top: 15px;
        display: flex;
        gap: 10px;
        justify-content: flex-end;
    }
    .required-mark {
        color: #dd4b39;
        margin-left: 3px;
    }
</style>

<section class="content-header">
    <h1>食物管理 <small>添加食物</small></h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-home"></i> 首页</a></li>
        <li><a href="#">食物管理</a></li>
        <li class="active">添加食物</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">食物信息录入</h3>
                </div>
                <form method="post" action="{% url 'myadmin_foods_add' %}" class="form-card">
                    {% csrf_token %}
                    
                    <!-- 基础信息 -->
                    <div class="form-section">
                        <h4><i class="fa fa-cutlery"></i> 基础信息</h4>
                        <div class="form-row">
                            <div class="form-col">
                                <div class="form-group">
                                    <label>食物名称 <span class="required-mark">*</span></label>
                                    <input type="text" name="food_name" class="form-control" required>
                                </div>
                                <div class="form-group">
                                    <label>所属类别 <span class="required-mark">*</span></label>
                                    <select name="category_id" class="form-control" required>
                                        {% for category in categories %}
                                        <option value="{{ category.id }}">{{ category.name }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                            </div>
                            <div class="form-col">
                                <div class="form-group">
                                    <label>食物描述</label>
                                    <textarea name="description" class="form-control" rows="4"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 营养成分 -->
                    <div class="form-section">
                        <h4><i class="fa fa-line-chart"></i> 营养成分（每100克）</h4>
                        <div class="form-row">
                            <div class="form-col">
                                <div class="form-group">
                                    <label>热量(大卡) <span class="required-mark">*</span></label>
                                    <input type="number" name="calories_per_100g" class="form-control" min="0" step="0.1" required>
                                </div>
                                <div class="form-group">
                                    <label>蛋白质(g)</label>
                                    <input type="number" name="protein_per_100g" class="form-control" min="0" step="0.1">
                                </div>
                                <div class="form-group">
                                    <label>脂肪(g)</label>
                                    <input type="number" name="fat_per_100g" class="form-control" min="0" step="0.1">
                                </div>
                            </div>
                            <div class="form-col">
                                <div class="form-group">
                                    <label>碳水化合物(g)</label>
                                    <input type="number" name="carbs_per_100g" class="form-control" min="0" step="0.1">
                                </div>
                                <div class="form-group">
                                    <label>膳食纤维(g)</label>
                                    <input type="number" name="fiber_per_100g" class="form-control" min="0" step="0.1">
                                </div>
                                <div class="form-group">
                                    <label>糖分(g)</label>
                                    <input type="number" name="sugar_per_100g" class="form-control" min="0" step="0.1">
                                </div>
                                <div class="form-group">
                                    <label>钠(mg)</label>
                                    <input type="number" name="sodium_per_100g" class="form-control" min="0" step="1">
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 特殊属性 -->
                    <div class="form-section">
                        <h4><i class="fa fa-tags"></i> 特殊属性</h4>
                        <div class="form-row">
                            <div class="form-col">
                                <div class="form-group">
                                    <label>饮食特性</label>
                                    <div class="checkbox-group">
                                        <div class="checkbox-item">
                                            <input type="checkbox" name="is_vegetarian" id="vegetarian">
                                            <label for="vegetarian">素食</label>
                                        </div>
                                        <div class="checkbox-item">
                                            <input type="checkbox" name="is_vegan" id="vegan">
                                            <label for="vegan">纯素</label>
                                        </div>
                                        <div class="checkbox-item">
                                            <input type="checkbox" name="is_gluten_free" id="glutenFree">
                                            <label for="glutenFree">无麸质</label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label>图片URL</label>
                                    <input type="url" name="image_url" class="form-control" placeholder="http://">
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 操作按钮 -->
                    <div class="btn-group">
                        <button type="button" class="btn btn-default" onclick="window.history.back();">返回</button>
                        <button type="reset" class="btn btn-default">重置</button>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
{% endblock %}